<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JVM 新生代内存分配详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: float 20s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translate(0, 0) rotate(0deg); }
            50% { transform: translate(-30px, -30px) rotate(180deg); }
        }
        
        .card-hover {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            position: relative;
            overflow: hidden;
        }
        
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: #2d2d2d;
            border-bottom: 1px solid #3e3e3e;
        }
        
        .code-block code {
            display: block;
            padding: 60px 24px 24px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .percentage-card {
            background: white;
            border-radius: 16px;
            padding: 24px;
            text-align: center;
            position: relative;
            overflow: hidden;
            transition: all 0.3s ease;
        }
        
        .percentage-card::before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            border-radius: 16px;
            opacity: 0;
            transition: opacity 0.3s ease;
            z-index: -1;
        }
        
        .percentage-card:hover::before {
            opacity: 1;
        }
        
        .percentage-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 20px 40px rgba(102, 126, 234, 0.2);
        }
        
        .percentage-card > * {
            position: relative;
            z-index: 1;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6 relative">
        <div class="max-w-6xl mx-auto relative z-10">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                <i class="fas fa-memory mr-4"></i>
                JVM 新生代内存分配机制
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl">
                深入理解 HotSpot JVM 中 Eden 区与 Survivor 区的黄金比例
            </p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>HotSpot JVM 中，新生代的堆内存通常分为三个区域：Eden 区和两个 Survivor 区（S0 和 S1）。这种精心设计的内存布局是 JVM 高效垃圾回收机制的基石，它确保了新创建对象的快速分配和存活对象的有效管理。
            </p>
        </div>

        <!-- Memory Distribution Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-chart-pie mr-3 text-gradient"></i>
                内存分配比例
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
                <div class="percentage-card">
                    <div class="text-5xl font-bold text-gradient mb-2">80%</div>
                    <h3 class="text-xl font-semibold mb-2">Eden 区</h3>
                    <p class="text-gray-600">新对象诞生地</p>
                    <i class="fas fa-seedling text-4xl text-green-400 mt-4"></i>
                </div>
                
                <div class="percentage-card">
                    <div class="text-5xl font-bold text-gradient mb-2">10%</div>
                    <h3 class="text-xl font-semibold mb-2">Survivor 0</h3>
                    <p class="text-gray-600">第一个幸存者区</p>
                    <i class="fas fa-shield-alt text-4xl text-blue-400 mt-4"></i>
                </div>
                
                <div class="percentage-card">
                    <div class="text-5xl font-bold text-gradient mb-2">10%</div>
                    <h3 class="text-xl font-semibold mb-2">Survivor 1</h3>
                    <p class="text-gray-600">第二个幸存者区</p>
                    <i class="fas fa-shield-alt text-4xl text-purple-400 mt-4"></i>
                </div>
            </div>

            <!-- Mermaid Diagram -->
            <div class="mermaid">
                graph LR
                    A[新生代内存] --> B[Eden 区 80%]
                    A --> C[Survivor 区 20%]
                    C --> D[S0 10%]
                    C --> E[S1 10%]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#48bb78,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#4299e1,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#ed64a6,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <div class="section-divider"></div>

        <!-- Design Philosophy -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6">
                <i class="fas fa-lightbulb mr-3 text-gradient"></i>
                设计理念
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="bg-gradient-to-br from-green-50 to-green-100 rounded-xl p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-expand-arrows-alt mr-3 text-green-600"></i>
                        Eden 区设计
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        Eden 区占据 80% 的新生代空间，为新创建的对象提供充足的分配空间。这种设计基于"大多数对象朝生夕死"的观察，确保了对象分配的高效性。
                    </p>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-blue-100 rounded-xl p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-compress-arrows-alt mr-3 text-blue-600"></i>
                        Survivor 区设计
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        两个 Survivor 区各占 10%，采用复制算法进行垃圾回收。这种双缓冲设计避免了内存碎片，同时为存活对象提供了晋升到老年代的缓冲地带。
                    </p>
                </div>
            </div>
        </div>

        <div class="section-divider"></div>

        <!-- Configuration Section -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6">
                <i class="fas fa-cogs mr-3 text-gradient"></i>
                配置与调优
            </h2>
            
            <p class="text-lg text-gray-700 mb-6">
                虽然默认的内存分配比例适用于大多数应用场景，但 JVM 提供了灵活的参数配置，允许开发者根据具体需求进行调整：
            </p>
            
            <div class="space-y-6">
                <div class="bg-gray-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-terminal mr-3 text-purple-600"></i>
                        关键 JVM 参数
                    </h3>
                    
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <code class="bg-gray-800 text-green-400 px-3 py-1 rounded-lg mr-4">-XX:NewRatio</code>
                            <p class="text-gray-700 flex-1">调整新生代与老年代的比例，影响整体内存分配策略</p>
                        </div>
                        
                        <div class="flex items-start">
                            <code class="bg-gray-800 text-green-400 px-3 py-1 rounded-lg mr-4">-XX:SurvivorRatio</code>
                            <p class="text-gray-700 flex-1">调整 Eden 区与 Survivor 区的比例，默认值为 8</p>
                        </div>
                    </div>
                </div>
                
                <div class="code-block">
                    <div class="absolute top-3 left-4 flex space-x-2">
                        <div class="w-3 h-3 bg-red-500 rounded-full"></div>
                        <div class="w-3 h-3 bg-yellow-500 rounded-full"></div>
                        <div class="w-3 h-3 bg-green-500 rounded-full"></div>
                    </div>
                    <code>java -XX:SurvivorRatio=8 -jar yourapp.jar</code>
                </div>
                
                <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-xl">
                    <p class="text-gray-700">
                        <i class="fas fa-info-circle mr-2 text-blue-600"></i>
                        此参数将 Survivor 区的大小设置为 Eden 区的 1/8，维持了默认的 8:1:1 比例关系。
                    </p>
                </div>
            </div>
        </div>

        <!-- Best Practices -->
        <div class="bg-gradient-to-br from-purple-600 to-pink-600 text-white rounded-2xl shadow-xl p-8">
            <h2 class="text-3xl font-bold mb-6">
                <i class="fas fa-star mr-3"></i>
                最佳实践建议
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-3">监控与分析</h3>
                    